Analytics and Attribution
Introduction
When we talk about analytics we mean a unified and comprehensive solution for collecting, processing, and analyzing data related to user interactions within a game. The attribution feature in our SDK allows you to accurately track the source of user acquisitions and attribute them to specific marketing campaigns, channels, or ad networks. This feature allows developers to gain valuable insights into user behavior, engagement, and the overall performance of their games.
Plankton's analytics and attribution feature supports providers such as Firebase, AppMetrica, AppsFlyer, and Tenjin.
Before you begin
Prerequisites
- Complete the Plankton setup
- For Android
- Set Target API Level to
33
or higher - Set Minimum Api Level to
19
or higher
- Set Target API Level to
- For iOS
- Set Target Minimum iOS Version to
15.0
or higher
- Set Target Minimum iOS Version to
You can change Minimum and Target versions in Unity from Edit > Project Settings > Player > Other Settings
Set up your accounts
Create and set up an account for each provider you want to use.
Firebase(Google Analytics)
- Sign into Firebase using your Google account.
- Create a Firebase Project and make sure that Google Analytics is enabled in it.
- Register your game with Firebase separately for Android and for iOS. Don't create app for Unity.
- Download the Firebase Android configuration file (
google-services.json
). This file is needed later in this guide.
Yandex AppMetrica
- Follow the steps in AppMetrica getting started guide and finish setting up your game in AppMetrica
- Retrieve the unique
API key
of your game from the AppMetrica's Settings page. This key is needed later in this guide.
AppsFlyer
- Visit AppsFlyer marketers guide to setup your AppsFlyer account and add your game.
- Retrieve the unique
Dev Key
of your game from its settings page in AppsFlyer dashboard.
Tenjin
- Follow the Tenjin getting started guide for marketers and finish setting up your game in Tenjin.
- Get the unique
SDK Key
from your app's page in Tenjin dashboard. This key is needed later in this guide.
Confiure Plankton settings
- Open plankton settings by going to
Edit > Project Settings > Plankton
. - Select the checkbox of the features that you want to use.
- Fill the required field
- It is
API Key
for AppMetrica,Dev Key
for AppsFlyer andSDK Key
for Tenjin. - For Firebase (Analytics and Remote Config) you should click "Open firebase json" and open your Firebase configuration file.(It is
google-services.json
in Android andGoogleService-Info.plist
in iOS.) - For Firebase, you can also enable Push Notification just by selecting its checkbox.
- For GameAnalytics you just select the checkbox. The configuration should be provided through code.
- It is
If you are using AppsFlyer on iOS, there are two extra fields that need to be filled.
- Apple App ID: Find it in your app's page in AppStore Connect, in
App Information > General Information> Apple ID
- Advertising attribution report endpoint URL: The URL which SKAN postback copies are sent to. According to AppsFlyer's official docs, set it to
https://appsflyer-skadnetwork.com/
.
Implementation
Let's dive into codes. Always import the Plankton
package in your scripts.
using Plankton;
Initialize
At first initialize the GeneralAnalytics
class like below:
GeneralAnalytics.Initialize();
After calling initialize, AppsFlyer and Tenjin will start their attribution process and gather user's install data.
Set user property
User properties (also known as profile attributes) are attributes you define to describe segments of your user base, such as gender, age, type of subscription, number of levels completed, and so on.
This is how you can set a user property:
var providers = Provider.Firebase | Provider.Yandex;
GeneralAnalytics.SetUserProperty(providers, "property_key", "property_value");
If you want to set a user property in multiple providers at the same time, you can add other providers with the binary literal |
.
SetUserProperty is not available for AppsFlyer and Tenjin.
Send event
Events provide insight on what is happening in your app, such as user actions, system events, or errors. They allow you to measure a specific interaction or occurrence in your game. For example, you can use an event to measure when someone opens a page, clicks a link, or completes a purchase, or to measure system behavior, such as when an app crashes or an impression is served.
Here's a sample of sending an event with three parameters:
var eventProviders = Provider.Firebase | Provider.Appsflyer | Provider.Yandex;
var parameters = new Dictionary<string, string>() {
{ "param_1", "value_1"},
{ "param_2", "value_2"},
{ "param_3", "value_3"},
};
GeneralAnalytics.LogEvent(eventProviders, "event_name", parameters);
If you want to send an event to multiple providers at the same time, you can add other providers with the binary literal |
.
If you simply want to send an event without any parameters, pass an empty Dictionary as parameters argument.
Analytics providers like Firebase usually log some events automatically. You can get more information about each provider's default events in their websites.
LogEvent is not available for Tenjin.
Track revenue
You can log every revenue you make from showing ads or selling in-app products with Plankton's TrackRevenue
method. It is actually a kind of event that is dedicated to logging revenue.
var providers = Provider.Firebase | Provider.Appsflyer | Provider.Yandex;
GeneralAnalytics.TrackRevenue(providers, "test_revenue", 2.99, "USD");
If you want to log revenue event in multiple providers at the same time, you can add other providers with the binary literal |
.
If you use Plankton for displaying ads in your game, it will automatically log ad's revenue with an event called "plankton_revenue"
Firebase Remote Configs
Firebase Remote Config is a cloud service that lets you change the behavior and appearance of your app without requiring users to update the app. When using Remote Config, you create in-app default values that control the behavior and appearance of your app. Then, you can later use the Firebase console or the Remote Config backend APIs to override in-app default values for all app users or for segments of your user base.
You can set key-value parameters in the Remote Configs section of your Firebase Analytics dashboard. For getting the values in your game, first you need to fetch the values from remote config backend. This is how you should fetch the remote config:
GeneralAnalytics.RemoteConfig.Fetch(json => Debug.Log($"Fetch Successfull! configs:{json}"), () => Debug.Log("Fetch Failed!"));
Now that you have successfully fetched the remote config, you can get parameter values by calling RemoteConfig.Get
method:
var configValue = GeneralAnalytics.RemoteConfig.Get("config_key", "default_value");
The second argument of this method is the default value in case the key which you are looking for does not exist in the configs.
Remote Config feature is only supported by Firebase.
API Refrences
Defined Types
In this section, we will discuss the enumerated types, variables, and classes associated with this feature:
Enums
GeneralAnalytics.Provider
Values | Description | Usage |
---|---|---|
Firebase | You can use Firebase Analytics as an analytics SDK in your game. You have to set up an account to be able to provide the needed credentials to use it. | GeneralAnalytics.Provider.Firebase |
Yandex | You can use AppMetrica as an analytics SDK in your game. You have to set up an account to be able to provide the needed credentials to use it. | GeneralAnalytics.Provider.Yandex |
Appsflyer | You can use AppsFlyer as a marketing attribution and an analytics SDK in your game. You have to set up an account to be able to provide the needed credentials to use it. | GeneralAnalytics.Provider.Appsflyer |
Tenjin | You can use Tenjin as a marketing attribution tool. Tenjin's attribution technology enables marketers to gain insight and context into why users engage with their apps. | GeneralAnalytics.Provider.Tenjin |
Method Summaries
Method | Arguments | Return Type | Description |
---|---|---|---|
Initialize | (no arguments) | void | You need to initialize GeneralAnalytics before using its features. |
SetUserProperty | Provider providers, string key, string value | void | Sets a user property to a given value. Up to 25 user property names are supported. Once set, user property values persist throughout the app lifecycle and across sessions. This method is supported by Firebase and Yandex. |
TrackRevenue | Provider providers, string eventName, double amount, string currency | void | You can use this method to track your revenue. |
LogEvent | Provider providers,string eventName, params object[] args | void | You can use this method to send events in your game. |
LogEvent | Provider providers, string eventName, Dictionary<string, string> args | void | You can use this method to send events in your game. |
RemoteConfig.Fetch | System.Action<string> onSucceed, System.Action onFailed | void | Asynchronously fetches and then activates the fetched configs from Firebase. |
RemoteConfig.Get | string key, string defaultValue | string | Gets remote config string value for the given key. |
RemoteConfig.Get | string key, int defaultValue | int | Gets remote config int value for the given key. |
RemoteConfig.Get | string key, float defaultValue | float | Gets remote config float value for the given key. |